from PyQt5.QtCore import QTimer
from PyQt5.QtGui import QMouseEvent, QIcon

from my_utils.utils_class.Base_button import BaseButton


class FWButton(BaseButton):
    def __init__(self, fw_obj, parent=None):
        super().__init__(normal_icon_path=":/icon/happy.png",
                         hit_icon_path=":/icon/no_happy.png",
                         speed=fw_obj.speed,
                         parent=parent)
        self.paused = None
        self.fw = fw_obj

    def mousePressEvent(self, event: QMouseEvent):
        self.setIcon(QIcon(self.hit_icon_path))
        self.fw.reduce_hp(10)
        super().mousePressEvent(event)

    def mouseReleaseEvent(self, event: QMouseEvent):
        # if self.fw.hp <= 0:
        #     QTimer.singleShot(100, self.cleanup)
        # else:
        self.setIcon(QIcon(self.normal_icon_path))
        self.move_randomly()
        self.timer.start(800)  # 重新计时
        super().mouseReleaseEvent(event)


